/*
 * Copyright (C) 2012 JiangHongTiao
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package sk.lieskove.jianghongtiao.paris.core.classify;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import sk.lieskove.jianghongtiao.common.utils.PropertiesUtils;
import sk.lieskove.jianghongtiao.websearch.enums.DocumentType;

/**
 * 
 * @author xjuraj e-mail: jjurco.sk_gmail.com
 */
public class BatchClassificationProperties implements Serializable {
    
    private transient PropertiesUtils pu = new PropertiesUtils(BatchClassificationProperties.class);
    private List<String> classifiers = new ArrayList<String>();
    private Integer loops = 1;
    private List<String> languages = new ArrayList<String>();
    private Integer wordsToKeep = 1000;
    private String joinDocTypesString = "";
    private Double baseline = 50.0;
    private DocumentType[] documentTypes = null;
    private String classificationGroup = UUID.randomUUID().toString();

    public BatchClassificationProperties(File propertyFile) {
        pu = PropertiesUtils.loadXMLFile(propertyFile);
        setClassifiersString(pu.getProperty("classifiers", ""));
        loops = new Integer(pu.getProperty("loops", "1"));
        setLanguages(pu.getProperty("languages", ""));
        wordsToKeep = new Integer(pu.getProperty("wordsToKeep", "1000"));
        joinDocTypesString = pu.getProperty("joinDocTypesString", "");
        baseline = new Double(pu.getProperty("baseline", "50"));
        setDocumentTypes(pu.getProperty("documentTypes", ""));
        this.classificationGroup = pu.getProperty("classificationGroup", 
                UUID.randomUUID().toString()+" (missing setting)");
    }

    public String getClassificationGroup() {
        return classificationGroup;
    }

    public void setClassificationGroup(String classificationGroup) {
        this.classificationGroup = classificationGroup;
    }
    
    public final void setDocumentTypes(String documentTypesString){
        String[] docTypes = documentTypesString.split(",");
        documentTypes = new DocumentType[docTypes.length];
        for (int i = 0; i < docTypes.length; i++) {
            documentTypes[i] = DocumentType.valueOf(docTypes[i].trim().toUpperCase());
        }
    }
    
    public final void setLanguages(String langString){
        languages.addAll(Arrays.asList(langString.split(",")));
    }
    
    public final void setClassifiersString(String classifiersString){
        for (String string : classifiersString.split(",")) {
            classifiers.add(string.trim());
        }
    }

    public Double getBaseline() {
        return baseline;
    }

    public void setBaseline(Double baseline) {
        this.baseline = baseline;
    }

    public List<String> getClassifiers() {
        return classifiers;
    }

    public void setClassifiers(List<String> classifiers) {
        this.classifiers = classifiers;
    }

    public DocumentType[] getDocumentTypes() {
        return documentTypes;
    }

    public void setDocumentTypes(DocumentType[] documentTypes) {
        this.documentTypes = documentTypes;
    }

    public String getJoinDocTypesString() {
        return joinDocTypesString;
    }

    public void setJoinDocTypesString(String joinDocTypesString) {
        this.joinDocTypesString = joinDocTypesString;
    }

    public List<String> getLanguages() {
        return languages;
    }

    public void setLanguages(List<String> languages) {
        this.languages = languages;
    }

    public Integer getLoops() {
        return loops;
    }

    public void setLoops(Integer loops) {
        this.loops = loops;
    }

    public PropertiesUtils getPu() {
        return pu;
    }

    public void setPu(PropertiesUtils pu) {
        this.pu = pu;
    }

    public Integer getWordsToKeep() {
        return wordsToKeep;
    }

    public void setWordsToKeep(Integer wordsToKeep) {
        this.wordsToKeep = wordsToKeep;
    }
    
    
}
